﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ITProject.Domain.Entities;
using System.ComponentModel.DataAnnotations;

namespace ITProject.WebUI.Models.ProjectAdmin
{
    public class ProjectAdminChangeFeatureStatusViewModel
    {
        public List<SelectListItem> StatusList { get; set; }
        [Required(ErrorMessage = "Musisz wybrać status")]
        [Display(Name = "Nowy status funkcjonalności")]
        public string ReturnStatus { get; set; }
        [Display(Name = "Nazwa funkcjonalności")]
        public string FeatureName { get; set; }
        [Display(Name = "Komentarz do zmiany statusu funkcjonalności")]
        public string Comment { get; set; }

        // ukryte
        public int FeatureId { get; set; }
        public string ProjectName { get; set; }

        public static ProjectAdminChangeFeatureStatusViewModel Convert(Feature feature, string projectName)
        { 
            ProjectAdminChangeFeatureStatusViewModel vm=new ProjectAdminChangeFeatureStatusViewModel();
            vm.ProjectName = projectName;
            vm.FeatureId = feature.Id;
            vm.FeatureName = feature.Name;
            vm.StatusList = new List<SelectListItem>();
            SelectListItem actualStatus = new SelectListItem { Selected = true, Text = StatusName.ConvertFromByte(feature.Status) };
            vm.StatusList.Add(actualStatus);
            if (StatusName.ConvertFromByte(feature.Status) != StatusName.Active)
            {
                SelectListItem status1 = new SelectListItem { Text = StatusName.Active };
                vm.StatusList.Add(status1);
            }
            if (StatusName.ConvertFromByte(feature.Status) != StatusName.Planned)
            {
                SelectListItem status1 = new SelectListItem { Text = StatusName.Planned };
                vm.StatusList.Add(status1);
            }
            if (StatusName.ConvertFromByte(feature.Status) != StatusName.Done)
            {
                SelectListItem status1 = new SelectListItem { Text = StatusName.Done };
                vm.StatusList.Add(status1);
            }
            if (StatusName.ConvertFromByte(feature.Status) != StatusName.Tested)
            {
                SelectListItem status1 = new SelectListItem { Text = StatusName.Tested };
                vm.StatusList.Add(status1);
            }
            if (StatusName.ConvertFromByte(feature.Status) != StatusName.Accepted)
            {
                SelectListItem status1 = new SelectListItem { Text = StatusName.Accepted };
                vm.StatusList.Add(status1);
            }
            return vm;
        }

        public static StatusChange Convert(ProjectAdminChangeFeatureStatusViewModel vm,Feature feature, int userId)
        {
            StatusChange sc = new StatusChange();
            sc.Comment = vm.Comment;
            sc.DateOfChange = DateTime.Now;
            sc.NewStatus = (byte)StatusName.ConvertFromString(vm.ReturnStatus);
            sc.OldStatus = feature.Status;
            sc.UserId = userId;
            return sc;
        }
    }
}